<?php
//                 表名，条件   ，字段名   ，限制显示条数，排序
function getlist($table,$where=1,$field='*',$limit=1000,$order='id desc'){
	$sql="select $field from $table where $where order by $order limit $limit";
	$result=mysql_query($sql) or die(mysql_error());
	$arr=array();
	while ($res=mysql_fetch_assoc($result)) {
		$arr[]=$res;
	};
	return $arr;
}
//                 表名，条件
function getone($table,$where=1){
	$sql="select * from $table where $where";
	$query=mysql_query($sql) or die(mysql_error());
	$arr=mysql_fetch_assoc($query);
	return $arr;
}
//                 表名，下标
function getcount($table,$as='totle'){
	$sql="select count(*) as $as from `$table`";
	$query=mysql_query($sql) or die(mysql_error());
	$arr=mysql_fetch_assoc($query);
	return $arr[$as];
}
//                 表名，数组    条件
function update($table,$data,$where){
	$str='';
	foreach ($data as $key => $value) {
		$str.="`$key`='$value',";
	}
	$str=substr($str,0,-1);
	$update="update $table set $str where $where";
	$result=mysql_query($update) or die(mysql_error());
	$row=mysql_affected_rows();
	return $row;
}
//                 表名，条件
function delete($table,$where){
	$delete="delete from $table where $where";
	mysql_query($delete) or die(mysql_error());
	$row=mysql_affected_rows();
	return $row;
}
//                 表名，数组
function insert($table,$data){
	$keystr='';
	$valstr='';
	foreach($data as $key => $value){
		$keystr.="`$key`,";
		$valstr.="'$value',";
	}
	$keystr=substr($keystr,0,-1);
	$valstr=substr($valstr,0,-1);

	$insert="insert into $table ($keystr)values($valstr)";
	mysql_query($insert) or die(mysql_error());;
	$row=mysql_affected_rows();
	return $row;
}
?>